import sqlite3

# 连接到SQLite数据库（如果数据库不存在，则会自动创建）
conn = sqlite3.connect('config.db')
c = conn.cursor()

# 创建一个新表（如果表不存在）
c.execute('''
    CREATE TABLE IF NOT EXISTS defects (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        defect_type TEXT NOT NULL,
        severity REAL NOT NULL,
        notification_method TEXT NOT NULL,
        notify_to TEXT NOT NULL
    )
''')

# 插入数据
c.execute('''
    INSERT INTO defects (defect_type, severity, notification_method, notify_to)
    VALUES ('Inclusion', 0.8, 'SMS', 'tech@example.com')
''')

# 提交更改
conn.commit()

# 查询数据
c.execute('SELECT * FROM defects')
rows = c.fetchall()
print("All Defects:")
for row in rows:
    print(row)

# 更新数据
c.execute('''
    UPDATE defects
    SET severity = 0.75
    WHERE defect_type = 'Inclusion'
''')
conn.commit()

# 查询更新后的数据
c.execute('SELECT * FROM defects WHERE defect_type = "Inclusion"')
updated_row = c.fetchone()
print("\nUpdated Defect:")
print(updated_row)

# 删除数据
c.execute('DELETE FROM defects WHERE defect_type = "Inclusion"')
conn.commit()

# 查询删除后的数据
c.execute('SELECT * FROM defects')
remaining_rows = c.fetchall()
print("\nRemaining Defects:")
for row in remaining_rows:
    print(row)

# 关闭连接
conn.close()
